/**
 *====================================================
 * 文件名称: BulkstockLatestCollectionServiceImpl.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    2015年10月21日	chenxy(创建:创建文件)
 *====================================================
 * 类描述：(说明未实现或其它不应生成javadoc的内容)
 */
package com.yuexunit.finance.bulkstock.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.bulkstock.entity.BulkstockLatestCollectionEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.util.StringUtil;

/**
 * @ClassName: BulkstockLatestCollectionServiceImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author chenxy
 * @date 2015年10月21日 20:20:37
 */
@Implements(BulkstockLatestCollectionService.class)
public class BulkstockLatestCollectionServiceImpl implements BulkstockLatestCollectionService {

	@Override
	public PageList<BulkstockLatestCollectionEntity> inquireBulkstockLatestCollectionPageList(Long categoryId, Long bulkstockInfoId, String bulkstockName, String specification, String region, Long dataSourceId,PageCriteria page) {
		DetachedCriteria dc = DetachedCriteria.forClass(BulkstockLatestCollectionEntity.class);
		if (categoryId != null) {
			dc.add(Restrictions.eq("categoryId", categoryId));
		}
		if (bulkstockInfoId != null) {
			dc.add(Restrictions.eq("bulkstockInfoId", bulkstockInfoId));
		}
		if (StringUtil.isNotBlank(bulkstockName)) {
			dc.add(Restrictions.like("bulkstockName", "%" + bulkstockName + "%"));
		}
		if (StringUtil.isNotBlank(specification)) {
			dc.add(Restrictions.like("specification", "%" + specification + "%"));
		}
		if (StringUtil.isNotBlank(region)) {
			dc.add(Restrictions.like("region", "%" + region + "%"));
		}
		if (dataSourceId != null) {
			dc.add(Restrictions.or(Restrictions.eq("dataSourceId", dataSourceId), Restrictions.eq("dataSourceId", null)));
		}
		dc.addOrder(Order.desc("collectionDate"));
		return PersistUtil.get(dc, page);
	}

	@Override
	public List<BulkstockLatestCollectionEntity> inquireBulkstockLatestCollectionList() {
		DetachedCriteria dc = DetachedCriteria.forClass(BulkstockLatestCollectionEntity.class);
		return PersistUtil.get(dc);
	}
}
